package Home_Work.src.day04;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Scanner;

/**
 * 通过控制台输入3个日期(yyyy-MM-dd格式)，然后转换为Date对象后存入
 * 集合，然后对该集合排序后输出所有日期。
 * @author Bonnie
 *
 */
public class Test08 {
	public static void main(String[] args) throws ParseException {
		System.out.println("请输入3个日期(yyyy-MM-dd)：");
		Scanner scanner1 = new Scanner(System.in);
		String str1 = scanner1.nextLine();
		String str2 = scanner1.nextLine();
		String str3 = scanner1.nextLine();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Date date1 = sdf.parse(str1);
		Date date2 = sdf.parse(str2);
		Date date3 = sdf.parse(str3);
		List<Date> list = new ArrayList();
		list.add(date1);
		list.add(date2);
		list.add(date3);
		Date temp = new Date();
		for(int i = 0; i < list.size(); i++) {
			for(int j = i + 1; j < list.size(); j++) {
				if(list.get(i).getTime() > list.get(j).getTime()) {
					temp = list.get(i);
					list.set(i, list.get(j));
					list.set(j, temp);
				}
			}
		}
		System.out.print("[");
		for(int i = 0; i < list.size(); i++) {
			System.out.print(sdf.format(list.get(i)));
			if(i != list.size() - 1) {
				System.out.print(", ");
			}
		}
		System.out.print("]");
	}
}
